{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "81cee167",
   "metadata": {},
   "source": [
    "---\n",
    "* 2023-10-18\n",
    "* 课程：Python语言\n",
    "* week05\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9fe87c5d",
   "metadata": {},
   "source": [
    "# 1. 用户输入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ef9e6f28",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：ls\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'ls'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input(\"请输入你的账号：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1f44b35e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：ls\n",
      "请输入你的密码：123\n"
     ]
    }
   ],
   "source": [
    "username = input(\"请输入你的账号：\")\n",
    "password = input(\"请输入你的密码：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "06b27656",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4b779f47",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：yessw\n",
      "请输入你的密码：12345\n",
      "你输入的账户或者密码错误\n"
     ]
    }
   ],
   "source": [
    "# 假设 正确的账号：yessw\n",
    "# 假设 正确的密码：123456\n",
    "\n",
    "# 登陆系统\n",
    "username = input(\"请输入你的账号：\")\n",
    "password = input(\"请输入你的密码：\")\n",
    "# 两种登陆可能，1：登陆成功，2：登陆失败\n",
    "if username == \"yessw\" and password == \"123456\": # 注意：两个等号表示等于的意思，上一次冒号携程中文了，下次要注意\n",
    "    # 情景1. 账户和密码都正确，则登陆成功\n",
    "    print(\"欢迎VVVIP账户回来~~\")\n",
    "else:\n",
    "    # 情景2：账户或者密码存在不正确的数据\n",
    "    print(\"你输入的账户或者密码错误\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "48f25e59",
   "metadata": {},
   "source": [
    "* 笔记：\n",
    "> 1. == 代表判断左右两边是否相等，即\"等于\"\n",
    "> 2. 所有的符号要用英文的符号，例如冒号  :"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8427a53",
   "metadata": {},
   "source": [
    "# 2. 用户输出（格式化）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79f91193",
   "metadata": {},
   "source": [
    "## 2.1 注释\n",
    "> 1. 注释的内容（code）是不会被执行的\n",
    "> 2. \\# 注释内容\n",
    "> 3. \"\"\" 注释内容 \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8494c667",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 第一种：# 表示单行注释，如上述用户输入的学习中，每一行进行文字描述的注释"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ab0445e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 第二种：\"\"\" 注释内容 \"\"\"  多行注释，用于记录之前写过的程序，不会被执行\n",
    "\"\"\"\n",
    "import random\n",
    "wait_time = random.randint(1,60)\n",
    "print(wait_time)\n",
    "\n",
    "word = \"bottles\"\n",
    "print(word)\n",
    "\"\"\"\n",
    "print(\"111\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1c946701",
   "metadata": {},
   "source": [
    "## 2.2 格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67543172",
   "metadata": {},
   "source": [
    "### 2.2.1 字符串的拼接实现格式化输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "07a3b26a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 指定格式的简历\n",
    "\n",
    "# 用户输入信息\n",
    "name = input(\"请输入你的姓名：\")\n",
    "age = input(\"请输入你的年龄：\")\n",
    "job = input(\"请输入你的职业：\")\n",
    "salary = input(\"请输入你的薪水：\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eec48d85",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 格式化输出内容\n",
    "\n",
    "INFO = \"\"\"-------- INFO \"\"\" + name + \"\"\" --------\n",
    "姓名：\"\"\" + name + \"\"\"\n",
    "年龄：\"\"\" + age + \"\"\"\n",
    "工作：\"\"\" + job + \"\"\"\n",
    "薪水：\"\"\" + salary\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e417ea69",
   "metadata": {},
   "source": [
    "* 笔记：上述代码使用的方法是\"字符串的拼接\"，用+实现"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c5de347f",
   "metadata": {},
   "source": [
    "### 2.2.2 占位符实现格式化输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1127692e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 格式化输出内容\n",
    "\n",
    "INFO = \"\"\"-------- INFO %s --------\n",
    "姓名：%s \n",
    "年龄：%s \n",
    "工作：%s\n",
    "薪水：%s\"\"\"%(name,name,age,job,salary)\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1c3e5e39",
   "metadata": {},
   "source": [
    "* 笔记：占位符比较适用于格式化字段较少的文本处理\n",
    "> 1. %s 占位符是字符串\n",
    "> 2. %d 占位符是数值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9694a293",
   "metadata": {},
   "source": [
    "### 2.2.3 格式化方法：format()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "426175b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 格式化输出内容\n",
    "\n",
    "# N:姓名，A:年龄,J：工作，S：薪水\n",
    "INFO = \"\"\"-------- INFO {N} --------\n",
    "姓名：{N} \n",
    "年龄：{A}\n",
    "工作：{J}\n",
    "薪水：{S}\"\"\".format(N = name,J = job, S = salary, A = age)\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c63b05c",
   "metadata": {},
   "source": [
    "* 笔记：format方法可以解决占位符的两个痛点：\n",
    "> 1. 不在考量位置顺序\n",
    "> 2. 解决重复字段出现的问题，只需要赋值一次，如上述：N = name，只需要写一次即可"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a23475c9",
   "metadata": {},
   "source": [
    "# 3. 课本第一章的三个项目"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "110d4019",
   "metadata": {},
   "source": [
    "## 3.1 项目一：判断时钟奇数分钟"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a6e2ddae",
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "odds = [  1, 3,  5,  7,  9, 11,13,15,17,19,\n",
    "             21,23,25,27,29,31,33,35,37,39,\n",
    "             41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "right_this_minute = datetime.today().minute\n",
    "\n",
    "if right_this_minute in odds:\n",
    "    print(\"This minute seems a little odd.\")\n",
    "else:\n",
    "    print(\"Not an odd minute.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bd2db01d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime\n",
    "datetime.today().second"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e3756132",
   "metadata": {},
   "source": [
    "## 3.2 项目二： 执行5次，每次等待随机秒钟，输出当前秒钟为奇数、偶数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "827b7552",
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_second = datetime.today().second\n",
    "    if right_this_second in odds:\n",
    "        print(\"This second seems a little odd.\")\n",
    "    else:\n",
    "        print(\"Not an odd second.\")\n",
    "    wait_time = random.randint(1,5)\n",
    "    time.sleep(wait_time) # 时间静止wait_time的时间\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5dacb60e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "24e6a04b",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(10):\n",
    "    print(random.random())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3d01c0d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(10):\n",
    "    print(random.randint(1,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "53c5b6cd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "201a75e9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "af2aea20",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
